package com.shelpe.services.scheduler.item.recommendword;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.beans.factory.annotation.Autowired;

import com.shelpe.services.scheduler.dto.AdgroupRecordDto;
import com.shelpe.services.scheduler.item.adgroup.AdgroupProcessor;
import com.shelpe.services.scheduler.po.Adgroups;
import com.shelpe.services.scheduler.po.SyncLog;
import com.shelpe.services.scheduler.syncclient.RecommendWordClient;

public class RecommendWordProcessor implements ItemProcessor<Adgroups, SyncLog>{

	private static final Logger logger = LoggerFactory.getLogger(AdgroupProcessor.class);
	
	@Autowired
	private RecommendWordClient reClient;
	
	
	@Override
	public SyncLog process(Adgroups item) throws Exception {
		// TODO Auto-generated method stub	
		SyncLog log = new SyncLog();
		Date beginProcessTime = new Date();
		long adgroupId = item.getAdgroupId();
		String nick = item.getNick();
		AdgroupRecordDto dto = new AdgroupRecordDto();
		
		dto.setNeedSync(true);
		dto.setNick(nick);	

		reClient.create(adgroupId, dto);
		reClient.metrics(adgroupId);
	
		log.setProcess("syncRecommendWord");	
		Date endProcessTime = new Date();
		long durTime = endProcessTime.getTime() - beginProcessTime.getTime();
		log.setDurTime(durTime);
		
		return log;
	}
	

}
